package com.pro.db.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pro.db.dao.BbsTopicMapper;
import com.pro.db.domain.BbsComment;
import com.pro.db.dao.BbsCommentMapper;
import com.pro.db.domain.BbsTopic;
import com.pro.db.service.itf.IBbsCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.security.UnresolvedPermission;

/**
 * <p>
 * 回复表 服务实现类
 * </p>
 *
 * @author wanglei
 * @since 2020-01-07
 */
@Service
public class BbsCommentServiceImpl extends ServiceImpl<BbsCommentMapper, BbsComment> implements IBbsCommentService {

    @Autowired
    BbsCommentMapper commentMapper;

    @Autowired
    BbsTopicMapper topicMapper;

    @Override
    public IPage<BbsComment> getMyComments(Page<BbsComment> page, Integer userId) {
        return commentMapper.getMyComments(page,userId);
    }

    @Override
    public void saveComment(BbsComment bbsComment) {
        commentMapper.insert(bbsComment);

        BbsTopic bbsTopic = topicMapper.selectById(bbsComment.getTopicId());
        BbsTopic update = new BbsTopic();
        update.setId(bbsTopic.getId());
        update.setCommentNum(bbsTopic.getCommentNum()+1);
        topicMapper.updateById(update);
    }
}
